Implement local_only by filtering the shortcuts and bookmarks list by
authorOwen Taylor <otaylor@redhat.com>
Mon, 15 Mar 2004 06:09:40 +0000 (06:09 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 15 Mar 2004 06:09:40 +0000 (06:09 +0000)
Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkfilechooserdefault.c: Implement local_only by
        filtering the shortcuts and bookmarks list by
        gtk_file_system_path_to_filename (file_system, path) != NULL.
        (#132894)

        * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
        a convenience function, may by interesting to push to the
        file system vtable later for performance.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooserdefault.c
gtk/gtkfilesystem.c
gtk/gtkfilesystem.h

index 79d21eeaefada6ed300c9b5a1171f8d0d9b22eb2..a9db2d1dbe1229b1672805fc8dd32bf2f174c1ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Implement local_only by
+       filtering the shortcuts and bookmarks list by 
+       gtk_file_system_path_to_filename (file_system, path) != NULL.
+       (#132894)
+
+       * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
+       a convenience function, may by interesting to push to the 
+       file system vtable later for performance.
+
 2004-03-14  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
index 79d21eeaefada6ed300c9b5a1171f8d0d9b22eb2..a9db2d1dbe1229b1672805fc8dd32bf2f174c1ca 100644 (file)
@@ -1,3 +1,14 @@
+Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Implement local_only by
+       filtering the shortcuts and bookmarks list by 
+       gtk_file_system_path_to_filename (file_system, path) != NULL.
+       (#132894)
+
+       * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
+       a convenience function, may by interesting to push to the 
+       file system vtable later for performance.
+
 2004-03-14  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
index 79d21eeaefada6ed300c9b5a1171f8d0d9b22eb2..a9db2d1dbe1229b1672805fc8dd32bf2f174c1ca 100644 (file)
@@ -1,3 +1,14 @@
+Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Implement local_only by
+       filtering the shortcuts and bookmarks list by 
+       gtk_file_system_path_to_filename (file_system, path) != NULL.
+       (#132894)
+
+       * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
+       a convenience function, may by interesting to push to the 
+       file system vtable later for performance.
+
 2004-03-14  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
index 79d21eeaefada6ed300c9b5a1171f8d0d9b22eb2..a9db2d1dbe1229b1672805fc8dd32bf2f174c1ca 100644 (file)
@@ -1,3 +1,14 @@
+Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Implement local_only by
+       filtering the shortcuts and bookmarks list by 
+       gtk_file_system_path_to_filename (file_system, path) != NULL.
+       (#132894)
+
+       * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
+       a convenience function, may by interesting to push to the 
+       file system vtable later for performance.
+
 2004-03-14  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
index 79d21eeaefada6ed300c9b5a1171f8d0d9b22eb2..a9db2d1dbe1229b1672805fc8dd32bf2f174c1ca 100644 (file)
@@ -1,3 +1,14 @@
+Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Implement local_only by
+       filtering the shortcuts and bookmarks list by 
+       gtk_file_system_path_to_filename (file_system, path) != NULL.
+       (#132894)
+
+       * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
+       a convenience function, may by interesting to push to the 
+       file system vtable later for performance.
+
 2004-03-14  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
index 4c36a05098ed7cb455843d72843d167708f2eb5b..86e7be4bc73cc57f4f689306e75a93a7b55ec9c2 100644 (file)
@@ -1065,6 +1065,10 @@ shortcuts_append_paths (GtkFileChooserDefault *impl,
       path = paths->data;
       error = NULL;
 
+      if (impl->local_only &&
+         !gtk_file_system_path_is_local (impl->file_system, path))
+       continue;
+
       /* NULL GError, but we don't really want to show error boxes here */
       if (shortcuts_insert_path (impl, start_row + num_inserted, FALSE, NULL, path, NULL, TRUE, NULL))
        num_inserted++;
@@ -1192,6 +1196,17 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
       GtkFileSystemVolume *volume;
 
       volume = l->data;
+      
+      if (impl->local_only)
+       {
+         GtkFilePath *base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
+         gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
+         gtk_file_path_free (base_path);
+
+         if (!is_local)
+           continue;
+       }
+
       shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL);
       n++;
     }
@@ -2909,6 +2924,37 @@ set_extra_widget (GtkFileChooserDefault *impl,
   impl->extra_widget = extra_widget;
 }
 
+static void
+set_local_only (GtkFileChooserDefault *impl,
+               gboolean               local_only)
+{
+  if (local_only != impl->local_only)
+    {
+      impl->local_only = local_only;
+
+      if (impl->shortcuts_model && impl->file_system)
+       {
+         shortcuts_add_volumes (impl);
+         shortcuts_add_bookmarks (impl);
+       }
+
+      if (local_only &&
+         !gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
+       {
+         /* If we are pointing to a non-local folder, make an effort to change
+          * back to a local folder, but it's really up to the app to not cause
+          * such a situation, so we ignore errors.
+          */
+         const gchar *home = g_get_home_dir ();
+         GtkFilePath *home_path = gtk_file_system_filename_to_path (impl->file_system, home);
+
+         _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), home_path, NULL);
+
+         gtk_file_path_free (home_path);
+       }
+    }
+}
+
 static void
 volumes_changed_cb (GtkFileSystem         *file_system,
                    GtkFileChooserDefault *impl)
@@ -3160,7 +3206,7 @@ gtk_file_chooser_default_set_property (GObject      *object,
       set_current_filter (impl, g_value_get_object (value));
       break;
     case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
-      impl->local_only = g_value_get_boolean (value);
+      set_local_only (impl, g_value_get_boolean (value));
       break;
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
       set_preview_widget (impl, g_value_get_object (value));
@@ -3605,6 +3651,17 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
   if (!check_is_folder (impl->file_system, path, error))
     return FALSE;
 
+  if (impl->local_only &&
+      !gtk_file_system_path_is_local (impl->file_system, path))
+    {
+      g_set_error (error,
+                  GTK_FILE_SYSTEM_ERROR,
+                  GTK_FILE_SYSTEM_ERROR_FAILED,
+                  _("Can't change to folder because it isn't local"));
+      
+      return FALSE;
+    }
+
   if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, error))
     return FALSE;
 
index 5ff8fecad32926c42013e028b60f1ab5138ddb3f..1b3430f2361eedc25bcd96670c9dcb2f03a59bab 100644 (file)
@@ -654,6 +654,33 @@ gtk_file_system_filename_to_path (GtkFileSystem *file_system,
   return GTK_FILE_SYSTEM_GET_IFACE (file_system)->filename_to_path (file_system, filename);
 }
 
+/**
+ * gtk_file_system_path_is_local:
+ * @filesystem: a #GtkFileSystem
+ * @path: A #GtkFilePath from that filesystem
+ * 
+ * Checks whether a #GtkFilePath is local; that is whether
+ * gtk_file_system_path_to_filename would return non-%NULL.
+ * 
+ * Return value: %TRUE if the path is loca
+ **/
+gboolean
+gtk_file_system_path_is_local (GtkFileSystem     *file_system,
+                              const GtkFilePath *path)
+{
+  gchar *filename;
+  gboolean result;
+    
+  g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
+  g_return_val_if_fail (path != NULL, FALSE);
+
+  filename = gtk_file_system_path_to_filename (file_system, path);
+  result = filename != NULL;
+  g_free (filename);
+
+  return result;
+}
+
 GdkPixbuf *
 gtk_file_system_render_icon (GtkFileSystem      *file_system,
                             const GtkFilePath  *path,
index 8503ff1ea00360dc271f48e11dd1e138222d03fc..98c80b84984dbe43462385dd8dc537749816b33f 100644 (file)
@@ -256,6 +256,9 @@ GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
                                               const gchar       *filename);
 
+gboolean     gtk_file_system_path_is_local    (GtkFileSystem     *filesystem,
+                                              const GtkFilePath *path);
+
 GdkPixbuf   *gtk_file_system_render_icon   (GtkFileSystem      *file_system,
                                            const GtkFilePath  *path,
                                            GtkWidget          *widget,